<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Exact-Value 精确值字段 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/_exact_value_fields.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/_exact_value_fields.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/_exact_value_fields.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/_exact_value_fields.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="search-in-depth.html">深入搜索</a></span>
»
<span class="breadcrumb-link"><a href="multi-field-search.html">多字段搜索</a></span>
»
<span class="breadcrumb-node">Exact-Value 精确值字段</span>
</div>
<div class="navheader">
<span class="prev">
<a href="_cross_fields_queries.html">« cross-fields 跨字段查询</a>
</span>
<span class="next">
<a href="proximity-matching.html">近似匹配 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="_exact_value_fields"></a>Exact-Value 精确值字段<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/110_Multi_Field_Search/55_Not_analyzed.asciidoc">edit</a>
</h2>
</div></div></div>
<p>在结束多字段查询这个话题之前，我们最后要讨论的是精确值 <code class="literal">not_analyzed</code> 未分析字段。将 <code class="literal">not_analyzed</code> 字段与 <code class="literal">multi_match</code> 中 <code class="literal">analyzed</code> 字段混在一起没有多大用处。</p>
<p>原因可以通过查看查询的 explanation 解释得到，设想将 <code class="literal">title</code> 字段设置成 <code class="literal">not_analyzed</code> ：</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">GET /_validate/query?explain
{
    "query": {
        "multi_match": {
            "query":       "peter smith",
            "type":        "cross_fields",
            "fields":      [ "title", "first_name", "last_name" ]
        }
    }
}</pre>
</div>
<div class="sense_widget" data-snippet="snippets/110_Multi_Field_Search/55_Not_analyzed.json"></div>
<p>因为 <code class="literal">title</code> 字段是未分析过的，Elasticsearch 会将 “peter smith” 这个完整的字符串作为查询条件来搜索！</p>
<pre class="literallayout">title:peter smith
(
    blended("peter", fields: [first_name, last_name])
    blended("smith", fields: [first_name, last_name])
)</pre>

<p>显然这个项不在 <code class="literal">title</code> 的倒排索引中，所以需要在 <code class="literal">multi_match</code> 查询中避免使用 <code class="literal">not_analyzed</code> 字段。</p>
</div>
<div class="navfooter">
<span class="prev">
<a href="_cross_fields_queries.html">« cross-fields 跨字段查询</a>
</span>
<span class="next">
<a href="proximity-matching.html">近似匹配 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>